package com.gdpu.controller;

import com.gdpu.api.CommonResult;
import com.gdpu.config.RedisConfig;
import com.gdpu.model.PmsCategory;
import com.gdpu.service.PortalPmsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:weiming
 * @Date:2021/6/10
 */
@Api(tags = "分类")
@RestController
@RequestMapping("/category")
public class PortalPmsCategoryController {

    @Autowired
    private PortalPmsCategoryService portalPmsCategoryService;

    @GetMapping("/first")
    @ApiOperation("获取一级分类")
    public CommonResult get(){
        List<PmsCategory> categoryList = portalPmsCategoryService.getAllParentCategory();
        HashMap<String, Object> map = new HashMap<>();
        map.put("categoryList",categoryList);
        if (categoryList != null) {
            return CommonResult.success(map);
        }
        return  CommonResult.failed();
    }

    @GetMapping("/{categroyId}")
    @ApiOperation("根据一级分类id获取子级分类")
    public CommonResult getChildByFirstCategroyId(@PathVariable(name = "categroyId")Integer categoryId){
        List<PmsCategory> categoryList = portalPmsCategoryService.getChildByFirstCategoryId(categoryId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("categoryList",categoryList);
        if (categoryList != null) {
            return CommonResult.success(map);
        }
        return  CommonResult.failed();
    }







}
